﻿using System;
using System.IO;

namespace Smart.Web.Mobile
{
    /// <summary>
    /// 
    /// </summary>
    public interface IPictgramRender
    {
        void Render(StreamWriter writer, Pictgram pictgram);
    }

    /// <summary>
    /// 
    /// </summary>
    public class NullRender : IPictgramRender
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="pictgram"></param>
        public void Render(StreamWriter writer, Pictgram pictgram)
        {
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class ThroughRender : IPictgramRender
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="pictgram"></param>
        public void Render(StreamWriter writer, Pictgram pictgram)
        {
            writer.Write( pictgram.Unicode );
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class UnicodeNumberRender : IPictgramRender
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="pictgram"></param>
        public void Render(StreamWriter writer, Pictgram pictgram)
        {
            writer.Write( String.Format( "&#x{0:X2}{1:X2};", pictgram.Unicode / 256, pictgram.Unicode % 256 ) );
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SjisNumberRender : IPictgramRender
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="pictgram"></param>
        public void Render(StreamWriter writer, Pictgram pictgram)
        {
            writer.Write( String.Format( "&#x{0:X2}{1:X2};", pictgram.Sjis[ 0 ], pictgram.Sjis[ 1 ] ) );
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class DocomoMixedRender : IPictgramRender
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="pictgram"></param>
        public void Render(StreamWriter writer, Pictgram pictgram)
        {
            if( pictgram.No < 1000 )
            {
                writer.Write( String.Format( "&#{0};", pictgram.Sjis[ 0 ] * 256 + pictgram.Sjis[ 1 ] ) );
            }
            else
            {
                writer.Write( String.Format( "&#x{0:X2}{1:X2};", pictgram.Unicode / 256, pictgram.Unicode % 256 ) );
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class ImgageLocalSrcRender : IPictgramRender
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="pictgram"></param>
        public void Render(StreamWriter writer, Pictgram pictgram)
        {
            writer.Write( String.Format( "<img localsrc=\"{0}\" />", pictgram.No ) );
        }
    }
}
